package flc.ast.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.DnsActivity;
import flc.ast.activity.ExploreActivity;
import flc.ast.activity.IpScanActivity;
import flc.ast.activity.MtrActivity;
import flc.ast.activity.NetworkDiagnosisActivity;
import flc.ast.activity.PortScanActivity;
import flc.ast.activity.QrCreateActivity;
import flc.ast.activity.TcpingActivity;
import flc.ast.activity.TracerouteActivity;
import flc.ast.activity.WebContrastActivity;
import flc.ast.adapter.NetworkAdapter;
import flc.ast.bean.MyNetworkBean;
import flc.ast.databinding.FragmentNetworkBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link NetworkFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class NetworkFragment extends BaseNoModelFragment<FragmentNetworkBinding> {

    private NetworkAdapter networkAdapter;
    private List<MyNetworkBean> listNetwork = new ArrayList<>();

    @Override
    protected int onCreate() {
        return R.layout.fragment_network;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.rvNetworkList.setLayoutManager(new GridLayoutManager(mContext, 3));
        networkAdapter = new NetworkAdapter();
        mDataBinding.rvNetworkList.setAdapter(networkAdapter);
        networkAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        switch (position) {
            case 0:
                startActivity(TracerouteActivity.class);
                break;
            case 1:
                startActivity(TcpingActivity.class);
                break;
            case 2:
                startActivity(MtrActivity.class);
                break;
            case 3:
                startActivity(ExploreActivity.class);
                break;
            case 4:
                startActivity(PortScanActivity.class);
                break;
            case 5:
                startActivity(DnsActivity.class);
                break;
            case 6:
                startActivity(NetworkDiagnosisActivity.class);
                break;
            case 7:
                startActivity(QrCreateActivity.class);
                break;
            case 8:
                startActivity(IpScanActivity.class);
                break;
            case 9:
                startActivity(WebContrastActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        String[] networkArray = getActivity().getResources().getStringArray(R.array.network_list);

        listNetwork.add(new MyNetworkBean(R.drawable.b1, networkArray[0]));
        listNetwork.add(new MyNetworkBean(R.drawable.b2, networkArray[1]));
        listNetwork.add(new MyNetworkBean(R.drawable.b3, networkArray[2]));
        listNetwork.add(new MyNetworkBean(R.drawable.b4, networkArray[3]));
//        listNetwork.add(new MyNetworkBean(R.drawable.b5, networkArray[4]));
        listNetwork.add(new MyNetworkBean(R.drawable.b6, networkArray[5]));
//        listNetwork.add(new MyNetworkBean(R.drawable.b7, networkArray[6]));
        listNetwork.add(new MyNetworkBean(R.drawable.b8, networkArray[7]));
        listNetwork.add(new MyNetworkBean(R.drawable.b9, networkArray[8]));
//        listNetwork.add(new MyNetworkBean(R.drawable.b10, networkArray[9]));
//        listNetwork.add(new MyNetworkBean(R.drawable.b11, networkArray[10]));
        listNetwork.add(new MyNetworkBean(R.drawable.b12, networkArray[11]));
        listNetwork.add(new MyNetworkBean(R.drawable.b13, networkArray[12]));
//        listNetwork.add(new MyNetworkBean(R.drawable.b14, networkArray[13]));
        listNetwork.add(new MyNetworkBean(R.drawable.b15, networkArray[14]));
        networkAdapter.setList(listNetwork);
    }
}